home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / store.h < prev    next >
C/C++ Source or Header  |  1993-05-13  |  7KB  |  159 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* store.h */
  20. /* Assignment-related macros */
  21.  
  22. /*
  23.  * Macros for storing a ref.  We use macros for storing into objects,
  24.  * since the storage manager needs to be able to track stores for
  25.  * save/restore and also for global/local checking.
  26.  * We also use macros for other ref assignments, because (as it happens)
  27.  * Turbo C generates pretty awful code for doing this.
  28.  *
  29.  * There are three cases that we need to distinguish:
  30.  *    - Storing to a stack (no special action);
  31.  *    - Storing into a newly created object (set l_new);
  32.  *    - Storing into a slot of an existing object (check l_new in
  33.  *        old value, set in new value).
  34.  * The macros are called
  35.  *    <make/store><new_type><case>(place_to_store, new_value)
  36.  * where <case> is nothing for storing to the stack, _new for storing into
  37.  * a new object, and _old for storing into an existing object.
  38.  * (The _old macros also take a client name for tracing and debugging.)
  39.  * <new_type> and new_value are chosen from the following alternatives:
  40.  *    ref_assign        POINTER TO arbitrary ref
  41.  *    make_t        type (only for null and mark)
  42.  *    make_tv        type, value field name, value
  43.  *              (only for scalars, which don't have attributes)
  44.  *    make_tav    type, attributes, value field name, value
  45.  *    make_tasv    type, attributes, size, value field name, value
  46.  * There are also specialized make_ macros for specific types:
  47.  *    make_array, make_int, make_real, make_bool, make_false, make_true,
  48.  *    make_mark, make_null, make_oper, make_[const_]string.
  49.  * Not all of the specialized make_ macros have _new and _old variants.
  50.  *
  51.  * For _tav and _tasv, we must store the value first, because sometimes
  52.  * it depends on the contents of the place being stored into.
  53.  */
  54.  
  55. /*
  56.  * Define the most efficient ref assignment macro for the platform.
  57.  */
  58. /* Assigning the components individually is fastest on Turbo C, */
  59. /* and on Watcom C when one or both of the addresses are */
  60. /* already known or in a register. */
  61. #define ref_assign_inline(pto,pfrom)\
  62.     ((pto)->value = (pfrom)->value,\
  63.      (pto)->tas = (pfrom)->tas)
  64. #ifdef __TURBOC__
  65.     /* Move the data in two 32-bit chunks, because */
  66.     /* otherwise the compiler calls SCOPY@. */
  67.     /* The cast to void is to discourage the compiler from */
  68.     /* wanting to deliver the value of the expression. */
  69. #  define ref_assign(pto,pfrom)\
  70.     (void)ref_assign_inline(pto, pfrom)
  71. #else
  72.     /* Trust the compiler and hope for the best. */
  73.     /* The MIPS compiler doesn't like the cast to void. */
  74. #  define ref_assign(pto,pfrom)\
  75.     (*(pto) = *(pfrom))
  76. #endif
  77.  
  78. /******
  79.  ****** NOTE: the declarations of alloc_save_*_mask, alloc_save_change,
  80.  ****** and alloc_[free_]array are duplicated from save.h.
  81.  ******/
  82. extern int alloc_save_new_mask;        /* l_new if in save, 0 if not */
  83. extern int alloc_save_test_mask;    /* 0 if in save, -1 if not */
  84. extern int alloc_save_change(P2(ref *ptr, const char *client_name));
  85. #define ref_save(pto,cname)\
  86.   (void)((r_type_attrs(pto) & l_new) == alloc_save_test_mask ?\
  87.      alloc_save_change(pto, cname) : 0)
  88. #define ref_mark_new(pto) ((pto)->tas.type_attrs |= alloc_save_new_mask)
  89. #define ref_assign_new(pto,pfrom)\
  90.   (void)(ref_assign(pto,pfrom), ref_mark_new(pto))
  91. #define ref_assign_old(pto,pfrom,cname)\
  92.   (ref_save(pto,cname), ref_assign_new(pto,pfrom))
  93. /* ref_mark_old is only needed in very unusual situations, namely, */
  94. /* when we want to do a ref_save just before a save instead of */
  95. /* when the actual assignment occurs. */
  96. #define ref_mark_old(pto) ((pto)->tas.type_attrs &= ~alloc_save_new_mask)
  97.  
  98. int alloc_array(P4(ref *paref, uint attrs, uint num_refs, const char *client_name));
  99. void alloc_free_array(P2(ref *paref, const char *client_name));
  100.  
  101. /* make_t must set the attributes to 0 to clear a_local! */
  102. #define make_t(pref,newtype) r_set_type_attrs(pref, newtype, 0)
  103. #define make_t_new(pref,newtype)\
  104.   r_set_type_attrs(pref, newtype, alloc_save_new_mask)
  105. #define make_t_old(pref,newtype,cname)\
  106.   (ref_save(pref,cname), make_t_new(pref,newtype))
  107.  
  108. #define make_tav(pref,newtype,newattrs,valfield,newvalue)\
  109.   ((pref)->value.valfield = (newvalue),\
  110.    r_set_type_attrs(pref, newtype, newattrs))
  111. #define make_tav_new(pref,t,a,vf,v)\
  112.   make_tav(pref,t,(a)|alloc_save_new_mask,vf,v)
  113. #define make_tav_old(pref,t,a,vf,v,cname)\
  114.   (ref_save(pref,cname), make_tav_new(pref,t,a,vf,v))
  115.  
  116. #define make_tv(pref,newtype,valfield,newvalue)\
  117.   make_tav(pref,newtype,0,valfield,newvalue)
  118. #define make_tv_new(pref,t,vf,v) make_tav_new(pref,t,0,vf,v)
  119. #define make_tv_old(pref,t,vf,v,cname) make_tav_old(pref,t,0,vf,v,cname)
  120.  
  121. #define make_tasv(pref,newtype,newattrs,newsize,valfield,newvalue)\
  122.   (make_tav(pref,newtype,newattrs,valfield,newvalue),\
  123.    r_set_size(pref, newsize))
  124. #define make_tasv_new(pref,t,a,s,vf,v)\
  125.   (make_tav_new(pref,t,a,vf,v), r_set_size(pref,s))
  126. #define make_tasv_old(pref,t,a,s,vf,v,cname)\
  127.   (make_tav_old(pref,t,a,vf,v,cname), r_set_size(pref,s))
  128.  
  129. /* Type-specific constructor macros */
  130.  
  131. #define make_array(pref,attrs,size,elts)\
  132.   make_tasv(pref, t_array, attrs, size, refs, elts)
  133. #define make_const_array(pref,attrs,size,elts)\
  134.   make_tasv(pref, t_array, attrs, size, const_refs, elts)
  135.  
  136. #define make_bool(pref,bval) make_tv(pref, t_boolean, index, bval)
  137. #define make_false(pref) make_bool(pref, 0)
  138. #define make_true(pref) make_bool(pref, 1)
  139.  
  140. #define make_int(pref,ival) make_tv(pref, t_integer, intval, ival)
  141. #define make_int_new(pref,ival) make_tv_new(pref, t_integer, intval, ival)
  142.  
  143. #define make_mark(pref) make_t(pref, t_mark)
  144.  
  145. #define make_null(pref) make_t(pref, t_null)
  146. #define make_null_new(pref) make_t_new(pref, t_null)
  147. #define make_null_old(pref,cname) make_t_old(pref, t_null, cname)
  148.  
  149. #define make_oper(pref,opidx,proc)\
  150.   make_tasv(pref, t_operator, a_executable, opidx, opproc, proc)
  151.  
  152. #define make_real(pref,rval) make_tv(pref, t_real, realval, rval)
  153. #define make_real_new(pref,rval) make_tv_new(pref, t_real, realval, rval)
  154.  
  155. #define make_string(pref,attrs,size,chars)\
  156.   make_tasv(pref, t_string, attrs, size, bytes, chars)
  157. #define make_const_string(pref,attrs,size,chars)\
  158.   make_tasv(pref, t_string, attrs, size, const_bytes, chars)
  159.